

local getmetatable = getmetatable
local setmetatable = setmetatable
local module = module
local require = require
local type = type
local error = error
local tonumber = tonumber
local tostring = tostring
local print = print

module('fit.PrimitiveFixture')
_VERSION='0.2'

local Fixture = require('fit.Fixture')

-- Format Converters ----------------------------

local function parseNum(cell)
    return tonumber(cell:text())
end

-- Answer Comparisons ---------------------------

local function check(self, cell, value)
    if type(value) == "number" then
        if self.parseNum(cell) == value then
            self:right(cell)
        else
            self:wrong(cell, value)
        end
    elseif type(value) == "string" then
        if  cell:text() == value then
            self:right(cell)
        else
            self:wrong(cell, value)
        end
    elseif type(value) == "boolean" then
        if (text:match("[tT][rR][uU][eE]") and value) then
            self:right(cell)
        elseif (text:match("[fF][aA][lL][sS][eE]") and not value) then
            self:right(cell)
        else
            self:wrong(cell, tostring(value))
        end
    else
        self:errorCell(cell, "Comparison of string to " .. type(value) ..
              " not currently supported")
    end
end

function __call()
    local aPrimitiveFixture = Fixture()

    aPrimitiveFixture.check = check
    aPrimitiveFixture.parseNum = parseNum

    return aPrimitiveFixture
end

setmetatable(_M, _M)
